package org.dairy.farms.dao.hibernate;

import org.dairy.farms.dao.ExpenseTypeDAO;
import org.dairy.farms.dao.RevenueTypeDAO;
import org.dairy.farms.dao.exception.PersistenceException;
import org.dairy.farms.dao.generic.AbstractDAOImpl;
import org.dairy.farms.model.ExpenseType;
import org.dairy.farms.model.RevenueType;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: gduggira
 * Date: Jul 13, 2011
 * Time: 3:54:27 PM
 */
@Repository("revenueTypeDao")
public class RevenueTypeDAOImpl extends AbstractDAOImpl<RevenueType, Long> implements RevenueTypeDAO {
    @Override
    public List<RevenueType> loadAll() {
        return basePersistence.loadAll(RevenueType.class);
    }

    @Override
    public RevenueType findByName(String revenueTypeName) {
        List<RevenueType> revenueTypes = basePersistence.findByProperty(RevenueType.class,"name",revenueTypeName);
        if(revenueTypes != null || revenueTypes.size() > 0){
            return revenueTypes.get(0);
        }else{
            throw new PersistenceException("Revenue Type with name "+revenueTypeName+" not found");
        }
    }
}
